package com.ruoyi.wechat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wechat.domain.WxScenicSpots;
import com.ruoyi.wechat.service.IWxScenicSpotsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 营地周边景点Controller
 * 
 * @author ruoyi
 * @date 2024-10-28
 */
@RestController
@RequestMapping("//spots")
public class WxScenicSpotsController extends BaseController
{
    @Autowired
    private IWxScenicSpotsService wxScenicSpotsService;

    /**
     * 查询营地周边景点列表
     */
    @PreAuthorize("@ss.hasPermi('wechart:spots:list')")
    @GetMapping("/list")
    public TableDataInfo list(WxScenicSpots wxScenicSpots)
    {
        startPage();
        List<WxScenicSpots> list = wxScenicSpotsService.selectWxScenicSpotsList(wxScenicSpots);
        return getDataTable(list);
    }

    /**
     * 导出营地周边景点列表
     */
    @PreAuthorize("@ss.hasPermi('wechart:spots:export')")
    @Log(title = "营地周边景点", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WxScenicSpots wxScenicSpots)
    {
        List<WxScenicSpots> list = wxScenicSpotsService.selectWxScenicSpotsList(wxScenicSpots);
        ExcelUtil<WxScenicSpots> util = new ExcelUtil<WxScenicSpots>(WxScenicSpots.class);
        util.exportExcel(response, list, "营地周边景点数据");
    }

    /**
     * 获取营地周边景点详细信息
     */
    @PreAuthorize("@ss.hasPermi('wechart:spots:query')")
    @GetMapping(value = "/{scenicId}")
    public AjaxResult getInfo(@PathVariable("scenicId") String scenicId)
    {
        return success(wxScenicSpotsService.selectWxScenicSpotsByScenicId(scenicId));
    }

    /**
     * 新增营地周边景点
     */
    @PreAuthorize("@ss.hasPermi('wechart:spots:add')")
    @Log(title = "营地周边景点", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WxScenicSpots wxScenicSpots)
    {
        return toAjax(wxScenicSpotsService.insertWxScenicSpots(wxScenicSpots));
    }

    /**
     * 修改营地周边景点
     */
    @PreAuthorize("@ss.hasPermi('wechart:spots:edit')")
    @Log(title = "营地周边景点", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WxScenicSpots wxScenicSpots)
    {
        return toAjax(wxScenicSpotsService.updateWxScenicSpots(wxScenicSpots));
    }

    /**
     * 删除营地周边景点
     */
    @PreAuthorize("@ss.hasPermi('wechart:spots:remove')")
    @Log(title = "营地周边景点", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scenicIds}")
    public AjaxResult remove(@PathVariable String[] scenicIds)
    {
        return toAjax(wxScenicSpotsService.deleteWxScenicSpotsByScenicIds(scenicIds));
    }
}
